package Offer2017;

/**
 * 字符串的排列
 * Created by 雷文康 on 2018/1/1.
 */
public class Test28 {
    public static void main(String[] args) {
        char[] ch= {'a', 'b', 'c'};
        permutation(ch);
    }

    public static void permutation(char[] ch) {
        if (ch == null || ch.length == 0) {
            return;
        }
        permutation(ch, 0, ch.length - 1);
    }

    private static void permutation(char[] ch, int start, int end) {
        if (start == end){
            System.out.print(ch);
            System.out.print(" ");
        }
        for (int i = start; i < ch.length; i++) {
            char temp = ch[start];
            ch[start] = ch[i];
            ch[i] = temp;
            permutation(ch, start + 1, end);
            temp = ch[start];
            ch[start] = ch[i];
            ch[i] = temp;
        }
    }

}
